package domain;

import java.awt.Point;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.Vector;

public class Board_Ass4 extends Board {

	private Vector<SquareIce>	_ices;
    private Point				_agentLocation;


	public Board_Ass4(String fileName, String assignment) {
		super(fileName, assignment);
	}

	@Override
    public void parse() {
		this._ices = new Vector<SquareIce>();
    	int row    = 0;
        try {
            BufferedReader in = new BufferedReader(new FileReader(_fileName));
            String str;
            while ((str = in.readLine()) != null) {
            	process(str, row);
                row++;
            }
            in.close();
        } catch (IOException e) {
            Debug.println(e.getMessage());
        }
	}

    private void process(String str, int row) {

        for (int column=0; column<str.length(); column++){
            char c = str.charAt(column);
            switch (c){
                case ' ':       // empty square
                    _board[row][column] = new SquareFree(row, column);
                    break;
                case '#':       // wall
                    _board[row][column] = new SquareWall(row, column);
                    break;
                case 'A':       // Agent (only one)
                    this._agentLocation = new Point(row, column);
                    break;
                default:
                	this._ices.addElement(new SquareIce(row, column, c-'0'));
                	break;
            }
        }
    }

	public Point getAgentLocation() {
		return this._agentLocation;
	}

	public Vector<SquareIce> get_ices() {
		return _ices;
	}
}
